Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

transfers: read various filter params in http request #474

Merged
merged 4 commits into from
Apr 7, 2020

Conversation

adamdecaf
Copy link
Member

Fixes: #455

query := `select transfer_id from transfers where user_id = ? and deleted_at is null`
func (r *SQLRepo) getUserTransfers(userID id.User, params transferFilterParams) ([]*model.Transfer, error) {
query := `select transfer_id from transfers
where user_id = ? and created_at >= ? and created_at <= ? and deleted_at is null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an index for created_at thats desc ?

Copy link
Member

@InfernoJJ InfernoJJ Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that its X or equal to Is it fine to get duplicates if they query this by sequential dates? ignore me lol doesn't apply here as I was thinking more about it,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no index on created_at desc for transfers. We should add one... Thanks for the catch

stmt, err := r.db.Prepare(query)
if err != nil {
return nil, err
}
defer stmt.Close()

rows, err := stmt.Query(userID)
rows, err := stmt.Query(userID, params.StartDate, params.EndDate, params.Limit, params.Offset)
Copy link
Member

@InfernoJJ InfernoJJ Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we query is params.EndDate time segment 23:59:999.000 ? I could have missed it but didn't see anything below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now() + "24 hours" basically. We could bump it forward more.

EndDate:   time.Now().Add(24 * time.Hour),

In the future we need to support #447 (scheduled transfers) where I think this endpoint should order by scheduled_at or created_at (coalesce the two) because transfers without scheduled_at are to be uploaded/posted on the current day.

fmt.Printf("params.EndDate=%v\n", params.EndDate)
}
if v := r.URL.Query().Get("limit"); v != "" {
params.Limit, _ = strconv.ParseInt(v, 10, 32)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to wrap these with a hard limit so we don't page tons and tons of objects back.

@codecov-io
Copy link

codecov-io commented Apr 7, 2020

Codecov Report

Merging #474 into master will increase coverage by 0.24%.
The diff coverage is 86.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
+ Coverage   58.33%   58.58%   +0.24%     
==========================================
  Files         112      114       +2     
  Lines        8302     8347      +45     
==========================================
+ Hits         4843     4890      +47     
  Misses       2735     2735              
+ Partials      724      722       -2     
Impacted Files Coverage Δ
internal/transfers/transfers.go 58.13% <73.07%> (+0.95%) ⬆️
internal/route/params.go 100.00% <100.00%> (ø)
internal/transfers/mock_transfer_repo.go 24.07% <100.00%> (ø)
internal/transfers/repository.go 66.06% <100.00%> (+0.30%) ⬆️
internal/util/time.go 100.00% <100.00%> (ø)
internal/filetransfer/outgoing.go 51.87% <0.00%> (+0.75%) ⬆️
internal/filetransfer/controller.go 62.04% <0.00%> (+3.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e18892a...8e160cf. Read the comment docs.

@adamdecaf adamdecaf merged commit 8e894c1 into moov-io:master Apr 7, 2020
@adamdecaf adamdecaf deleted the filter-transfers-by-date branch April 7, 2020 19:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transfers: handle startDate and endDate query params
3 participants